
alter  proc sp_save_endcustomer_list
@customerId int,
@endCustomerId int
as
begin

	declare @status_id int
	
	if(( select count(*) from Customer_endcustomer_relationship where ParentCustomer_ID = @customerId and EndCustomer_ID = @endCustomerId) = 0)
	begin
		select @status_id = RelationshipStatus_ID from Customer_Relationship_Status where Name = 'Active'
		--print 'This is test message'
		insert into customer_endcustomer_relationship(ParentCustomer_ID, EndCustomer_ID, RelationshipStatus_ID) values (@customerId, @endCustomerId, @status_id)
	end
	else
	begin
		select @status_id = RelationshipStatus_ID from Customer_Relationship_Status where Name = 'Active'
		update Customer_endcustomer_relationship set ParentCustomer_ID = @customerId, EndCustomer_ID = @endCustomerId, RelationshipStatus_ID = @status_id where ParentCustomer_ID = @customerId and EndCustomer_ID = @endCustomerId
	end		
end
